package com.atguigu.func;

import com.atguigu.utils.KeyWordUtil;
import com.atguigu.utils.MyKeyWordUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

import java.util.List;

//自定义UDTF:切分单词
@FunctionHint(output = @DataTypeHint("ROW<word string>"))//设置输出的字段别名和字段类型，
public class MySplitFunction extends TableFunction {
    public void eval(String keyword){
        try {
            List<String> words = MyKeyWordUtil.splitKeyWord(keyword);
            for (String word : words) {
                //能切的话就把keyword切分成一个个单词输出出去
                collect(Row.of(word));
            }
        } catch (Exception e) {
            //切不了就把这个单词整体输出出去
            collect(Row.of(keyword));
        }


    }
}
